package com.shyb.lingxian.netWork;

import android.util.Log;

import retrofit2.adapter.rxjava.HttpException;
import rx.Subscriber;

/**
 * Created by gs on 2018/3/23.
 */

public abstract class RequestCallback<M> extends Subscriber<M> {

    public abstract void onSuccess(M model);
    public abstract void onFailure(String message);
    public abstract void onFinish();

    @Override
    public void onError(Throwable e) {

        if (e instanceof HttpException) {
            HttpException httpException = (HttpException) e;
            String message = httpException.getMessage();
            Log.e("NetWork_error",message);

        } else {
            onFailure(e.getMessage());

        }
        onFinish();

    }

    @Override
    public void onNext(M model) {
        Log.e("返回数据2:",model+".");

        onSuccess(model);
    }

    @Override
    public void onCompleted() {
        onFinish();
    }
}
